#! /usr/bin/env python
#coding=utf-8
from HTMLParser import HTMLParser

class HTMLResponseParser(HTMLParser):
	__pastebin_magic__ = ""
	
	def handle_starttag(self, tag, attrs):
		if tag == "input":
			#print "Encountered the beginning of a %s tag" % tag
			if len(attrs) == 0:
				pass
			else:
				for (key, value) in attrs:
					if ((key == "id") and (value == "spam_pid")):
						# found the hard code magic number, re enumerate
						for (k, v) in attrs:
							if k == "value":
								self.__pastebin_magic__ = v;
								print "magic number %s founded in HTML response" % self.__pastebin_magic__
							else:
								pass;
					else:
						pass;
		else:
			#print "No magic number found in HTML response" 
			pass;
	def pastebin_magic(self):
		return self.__pastebin_magic__;

if __name__ == "__main__":
	# create new session
    # test routine
